<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:p="http://primefaces.org/ui"
                xmlns:cc="http://java.sun.com/jsf/composite"
                template="../../template/tagedu.xhtml">
    
    <cc:interface>
        <cc:attribute name="hParent" default="false"/>
        <cc:attribute name="human" required="true"/>
        <cc:attribute name="button" rendered="true" method-signature="void action()"/>
    </cc:interface>
    
    <cc:implementation>
        <p:tabView id="actorTab">
            <p:tab title="Dados Principais">
                <p:panel styleClass="mainInfoTab">
                    <h:panelGrid columns="2" styleClass="panelGrids">
                        <h:outputLabel for="name" value="Nome*:"/>
                        <p:inputText id="name" value="#{cc.attrs.human.firstName}" styleClass="name"
                                    required="true" requiredMessage="'Nome' é obrigatório"/>

                        <h:outputLabel for="lastName" value="Sobrenome*:"/>
                        <p:inputText id="lastName" styleClass="name" value="#{cc.attrs.human.lastName}"
                                    required="true" requiredMessage="'Sobrenome' é obrigatório"/>

                        <h:outputLabel for="sex" value="Sexo*:" 
                                       rendered="#{newActorMB.canChangeSex(cc.attrs.human)}"/>
                        <h:selectOneMenu id="sex" value="#{cc.attrs.human.sex}" 
                                         rendered="#{newActorMB.canChangeSex(cc.attrs.human)}">
                            <f:selectItem itemLabel="Masculino" itemValue="#{enumeationUtil.male}"/>
                            <f:selectItem itemLabel="Feminino" itemValue="#{enumeationUtil.female}"/>
                        </h:selectOneMenu>

                        <h:outputLabel for="birthday" value="Nascimento*:"/>
                        <p:inputMask id="birthday" mask="99/99/9999" required="true" 
                                    requiredMessage="'Nascimento' é obrigatório" value="#{cc.attrs.human.birthday.time}">
                            <f:convertDateTime pattern="dd/MM/yyyy"/>
                        </p:inputMask>

                        <h:outputLabel for="nacionality" value="Nacionalidade*:"/>
                        <h:selectOneMenu id="nacionality" value="#{cc.attrs.human.nationality}" converter="nationalityC">
                            <f:selectItems value="#{newActorMB.allNationality}" var="nat" itemLabel="#{nat.name}"/>
                        </h:selectOneMenu>

                        <h:outputLabel for="ethnicity" value="Etnia*:"/>
                        <h:selectOneMenu id="ethnicity" value="#{cc.attrs.human.ethnicity}" converter="ethnicityC">
                            <f:selectItems value="#{newActorMB.allEthnicity}" var="et" itemLabel="#{et.name}"/>
                        </h:selectOneMenu>

                        <h:outputLabel for="phone" value="Telefone Fixo:"/>
                        <p:inputMask id="phone" mask="(99)9999-9999" value="#{cc.attrs.human.phone}"/>

                        <h:outputLabel for="celphone" value="Celular:"/>
                        <p:inputMask id="celphone" mask="(99)9999-9999" value="#{cc.attrs.human.celphone}"/>

                        <h:outputLabel for="email" value="Email:"/>
                        <p:inputText id="email" value="#{cc.attrs.human.email}"/>

                        <h:outputLabel for="laterality" value="Lateralidade*:"/>
                        <h:selectOneMenu id="laterality" value="#{cc.attrs.human.laterality}">
                            <f:selectItem itemValue="#{enumeationUtil.rightHanded}" itemLabel="Destro"/>
                            <f:selectItem itemValue="#{enumeationUtil.leftHanded}" itemLabel="Canhoto"/>
                            <f:selectItem itemValue="#{enumeationUtil.ambidextrous}" itemLabel="Ambdestro"/>
                        </h:selectOneMenu>

                        <h:outputLabel for="maritalStatus" value="Estado Civil*:"/>
                        <h:selectOneMenu id="maritalStatus" value="#{cc.attrs.human.maritalStatus}">
                            <f:selectItem itemValue="#{enumeationUtil.single}" itemLabel="Solteiro(a)"/>
                            <f:selectItem itemValue="#{enumeationUtil.married}" itemLabel="Casado(a)"/>
                            <f:selectItem itemValue="#{enumeationUtil.divorced}" itemLabel="Divorciado(a)"/>
                            <f:selectItem itemValue="#{enumeationUtil.widowed}" itemLabel="Viúvo(a)"/>
                        </h:selectOneMenu>

                    </h:panelGrid>
                </p:panel>
            </p:tab>

            <p:tab title="Endereço">
                <p:panel id="address" styleClass="addressPanel">
                    <h:outputLabel value="CEP" for="cep"/>
                    <p:inputMask id="cep" value="#{cc.attrs.human.address.zipcode.code}" mask="99999999" required="true" requiredMessage="'CEP' é obrigatório"/>
                    <p:commandButton value="Buscar" ajax="true" action="#{addressMB.searchCEP(cc.attrs.human.address)}" update="address" process="@this, cep"/>
                    <br/>
                    <h:panelGroup id="zipcode">
                        <h:outputLabel value="Estado:" for="state"/>
                        <p:inputText id="state" value="#{cc.attrs.human.address.zipcode.city.state.name}" required="true" readonly="true"/>
                        <br/>
                        <h:outputLabel value="Cidade:" for="city"/>
                        <p:inputText id="city" value="#{cc.attrs.human.address.zipcode.city.name}" required="true" readonly="true"/>
                        <br/><br/>
                    </h:panelGroup>
                    <h:panelGrid rendered="#{cc.attrs.human.address.zipcode.id != null}" columns="2">
                        <h:outputLabel value="Bairro:" for="neighborhood"/>
                        <p:autoComplete id="neighborhood" value="#{cc.attrs.human.address.neighborhood.name}" 
                                        completeMethod="#{addressMB.neighborhoodComplete(query,cc.attrs.human.address)}" 
                                        required="true" requiredMessage="'Bairro' é campo obrigatório"
                                        minQueryLength="3"/>
                        <h:outputLabel value="Logradouro:" for="street"/>
                        <p:autoComplete id="street" value="#{cc.attrs.human.address.street.name}" 
                                        completeMethod="#{addressMB.streetComplete(query,cc.attrs.human.address)}" 
                                        required="true" requiredMessage="'Logradouro' é campo obrigatório"  
                                        minQueryLength="3"/>
                        <h:outputLabel value="Número:" for="number"/>
                        <p:inputText id="number" value="#{cc.attrs.human.address.number}"/>
                        <h:outputLabel value="Complemento" for="complement"/>
                        <p:inputText id="complement" value="#{cc.attrs.human.address.complement}"/>                            
                    </h:panelGrid>
                </p:panel>
            </p:tab>

            <p:tab title="Dados Específicos">
                <p:panel>
                    <h:panelGrid columns="2" styleClass="panelGrids">
                        <ui:repeat value="#{cc.attrs.human.additionalInfos}" var="additionalInfo" rendered="#{!cc.attrs.hParent}">
                            <h:outputText styleClass="specificInfo" value="#{additionalInfo.additionalInfoType.acronym}*:"/>
                            <p:inputMask id="addInfoMask" mask="#{additionalInfo.additionalInfoType.mask}"
                                        value="#{additionalInfo.value}"
                                        required="#{additionalInfo.additionalInfoType.compulsory}"
                                        requiredMessage="'#{additionalInfo.additionalInfoType.acronym}' é obrigatório"/>
                        </ui:repeat>
                    </h:panelGrid>
                    <h:panelGroup id="addInfoPanel" layout="block" rendered="#{cc.attrs.hParent}">
                        <h:selectOneMenu id="addInfoTypes" value="#{cc.attrs.human.additionalInfos[0].additionalInfoType}" converter="infoTypeC"
                                         rendered="true" requiredMessage="A seleção de um registro é obrigatória">
                            <f:selectItem value="#{null}" itemLabel="Selecione um registro"/>
                            <f:selectItems value="#{newActorMB.addInfoTypeList}" var="infoType" itemLabel="#{infoType.name}"/>
                            <f:ajax execute="addInfoTypes" render="addInfoPanel"/>
                        </h:selectOneMenu>
                        <p:inputMask mask="#{cc.attrs.human.additionalInfos[0].additionalInfoType.mask}"
                                     value="#{cc.attrs.human.additionalInfos[0].value}"
                                     required="true" requiredMessage="É obrigatório preencher o registro"/>
                    </h:panelGroup>
                </p:panel>
            </p:tab>

            <p:tab title="Filiação" rendered="#{!cc.attrs.hParent}">
                <h:panelGroup id="filiation">
                    <p:panel header="Pai" style="height: 100px">
                        <p:commandLink value="Buscar" ajax="true"
                                    process="@this"
                                    oncomplete="searchHuman.show();" 
                                    action="#{newActorMB.prepareSearch(enumeationUtil.male)}"
                                    update=":searchHumanDialog"/>
                        <br/>
                        <p:commandLink value="Cadastrar" ajax="true"
                                    process="@this"
                                    oncomplete="addHuman.show();" 
                                    action="#{newActorMB.prepareNewHuman(enumeationUtil.male)}"
                                    update=":addHumanDialog"/>
                        <br/><br/>
                        <h:outputLabel value="Nome: "/>
                        <h:outputText rendered="#{cc.attrs.human.father != null}"
                                    value="#{cc.attrs.human.father.name}"/>
                    </p:panel>
                    <p:panel header="Mãe" style="height: 100px">
                        <p:commandLink value="Buscar" ajax="true"
                                    process="@this"
                                    oncomplete="searchHuman.show();" 
                                    action="#{newActorMB.prepareSearch(enumeationUtil.female)}"
                                    update=":searchHumanDialog"/>
                        <br/>
                        <p:commandLink value="Cadastrar" ajax="true"
                                    process="@this"
                                    oncomplete="addHuman.show();" 
                                    action="#{newActorMB.prepareNewHuman(enumeationUtil.female)}"
                                    update=":addHumanDialog"/>
                        <br/><br/>
                        <h:outputLabel value="Nome: "/>
                        <h:outputText rendered="#{cc.attrs.human.mother != null}"
                                    value="#{cc.attrs.human.mother.name}"/>
                    </p:panel>
                    <p:panel header="Responsável" style="height: 100px">
                        <p:commandLink value="Buscar" ajax="true"
                                    process="@this"
                                    oncomplete="searchHuman.show();"
                                    action="#{newActorMB.prepareSearch(null)}"
                                    update=":searchHumanDialog"/>
                        <br/>
                        <p:commandLink value="Cadastrar" ajax="true"
                                    process="@this"
                                    oncomplete="addHuman.show();" 
                                    action="#{newActorMB.prepareNewHuman(null)}"
                                    update=":addHumanDialog"/>
                        <br/><br/>
                        <h:outputLabel value="Nome: "/>
                        <h:outputText rendered="#{cc.attrs.human.sponsor != null}"
                                    value="#{cc.attrs.human.sponsor.name}"/>
                    </p:panel>
                </h:panelGroup>
            </p:tab>

            <p:tab title="Registro" rendered="#{!cc.attrs.hParent}">
                <p:panel>
                    <h:panelGrid columns="1" styleClass="panelGrids">
                        <h:panelGroup id="unitiesForRegister">
                            <h:outputLabel for="unity" value="Local*:"/>
                            <h:selectOneMenu id="unity" value="#{newActorMB.unity}" converter="unityC" 
                                            required="true" requiredMessage="'Local' é obrigatório">
                                <f:selectItem itemLabel="Selecione um local" itemValue="#{null}" noSelectionOption="true"/>
                                <f:selectItems value="#{newActorMB.findUnitys}" var="unity" itemLabel="#{unity.name}"/>                     
                            </h:selectOneMenu>
                        </h:panelGroup>
                    </h:panelGrid>
                </p:panel>
            </p:tab>
        </p:tabView>
    </cc:implementation>
</ui:composition>

